use std::collections::HashMap;

struct Solution {}

fn main() {}

impl Solution {
    pub fn unique_occurrences(arr: Vec<i32>) -> bool {
        let mut num_cnt_map: HashMap<i32, i32> = HashMap::new();
        arr.iter().for_each(|x| { Self::add_cnt_to_map(&mut num_cnt_map, x); });

        Self::has_repeat_cnt(&mut num_cnt_map)
    }

    fn has_repeat_cnt(num_cnt_map: &mut HashMap<i32, i32>) -> bool {
        let mut cnt_map: HashMap<i32, i32> = HashMap::new();
        for entry in num_cnt_map.iter() {
            if cnt_map.contains_key(entry.1) {
                return false;
            }
            cnt_map.insert(*entry.1, *entry.0);
        }
        return true;
    }

    pub fn add_cnt_to_map(cnt_map: &mut HashMap<i32, i32>, num: &i32) {
        if cnt_map.contains_key(&num) {
            cnt_map.insert(*num, cnt_map.get(&num).unwrap() + 1);
        } else {
            cnt_map.insert(*num, 1);
        }
    }
}